                $(function () {

    var loginUrl = '/o2o/local/logincheck';

    var usertype = getQueryString('usertype');

    //登陆次数
    var loginCount = 0;

    $('#submit').click(function () {
        var userName = $('#username').val();
        var password = $('#psw').val();
        var verifyCodeActual = $('#j_captcha').val();

        //是否需要验证信息 false为不需要
        var needVerify = false;
        //如果登陆三次都失败
        if (loginCount >= 3) {
            //那么就需要验证码校验了`
            if (!verifyCodeActual) {
                $.toast('请输入验证码！');
                return;
            } else {
                needVerify = true;
            }
        }

        /**
         * 提交
         */
        $.ajax({
            url: loginUrl,
            type: 'post',
            dataType: 'json',
            data: {
                userName: userName,
                password: password,
                verifyCodeActual: verifyCodeActual,
                needVerify: needVerify
            },
            success: function (data) {
                if (data.success) {
                    $.toast("登陆成功!");
                    if (usertype == 1) {
                        window.location.href = '/o2o/frontend/index';
                    } else {
                        window.location.href = '/o2o/shopadmin/shoplist';
                    }
                } else {
                    $.toast("登陆失败!" + data.errMsg);
                    loginCount++;
                    if (loginCount >= 3) {
                        $('#verifyPart').show();
                    }
                }
            }
        });
    });


})